package com.china08.yxyapi.repository.db;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLessonItem;

public interface YxyLessonsSchoolLessonItemRepository extends JpaRepository<YxyLessonsSchoolLessonItem, String> {

    List<YxyLessonsSchoolLessonItem> findByChapterIdAndStatusNotOrderByOrderNum(String chapterId, Integer status);

    YxyLessonsSchoolLessonItem findById(String itemId);

    List<YxyLessonsSchoolLessonItem> findByLessonId(String lessonId);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndStatusAndCreatedDateLessThanOrderByCreatedDateDesc(String lessonId, Integer status, Date createDate);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndStatusAndCreatedDateGreaterThanOrderByCreatedDateAsc(String lessonId, Integer status, Date createDate);

    @Query(value = " select t1 from YxyLessonsSchoolLessonItem t1 where t1.lessonId = ?1 and t1.status = ?2 order by t1.createdDate desc")
    List<YxyLessonsSchoolLessonItem> findLessonItemsrByLessonId(String lessonId, Integer status);

    YxyLessonsSchoolLessonItem findTop1ByOrderNumLessThanOrderByOrderNumDesc(Integer orderNum);

    YxyLessonsSchoolLessonItem findTop1ByOrderNumGreaterThanOrderByOrderNumAsc(Integer orderNum);

    Integer countByLessonIdIn(List<String> idOnes2);

    Integer countByChapterId(String chapter);

    Integer countByLessonId(String lessonId);

    Integer countByLessonIdAndIdIn(String lessonId, List<String> itemsIds);

    @Query(value = " select max(t1.orderNum)  from YxyLessonsSchoolLessonItem t1 where t1.chapterId = ?1")
    Integer findMaxOrderNumLessonItemByLessonId(String chapterId);

    @Query(value = " select t1 from YxyLessonsSchoolLessonItem t1 where t1.lessonId = ?1 and t1.chapterId = ?2 and t1.videoId = ?3 and t1.status = ?4 order by t1.createdDate desc")
    List<YxyLessonsSchoolLessonItem> findYxyItemByLessonIdAndChapterIdAndVideoId(String lessonId, String chapterId, String video, Integer status);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndStatusNotAndOrderNumLessThanOrderByOrderNumDesc(String lessonId, Integer status, Integer itemOrderNum);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndStatusNotAndOrderNumGreaterThanOrderByOrderNumAsc(String lessonId, Integer status, Integer itemOrderNum);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndOrderNumLessThanAndStatusNotOrderByOrderNumDesc(String lessonId, Integer itemOrderNum, int i);

    YxyLessonsSchoolLessonItem findTop1ByLessonIdAndOrderNumGreaterThanAndStatusNotOrderByOrderNumAsc(String lessonId, Integer itemOrderNum, int i);

    List<YxyLessonsSchoolLessonItem> findByChapterIdAndStatusNotOrderByOrderNumAsc(String id, int i);
}
